package com.hmall.gateway.fiters;


import org.springframework.cloud.gateway.filter.GatewayFilterChain;
import org.springframework.cloud.gateway.filter.GlobalFilter;
import org.springframework.core.Ordered;
import org.springframework.http.HttpHeaders;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.stereotype.Component;
import org.springframework.web.server.ServerWebExchange;
import reactor.core.publisher.Mono;


//自定义过滤器
@Component // 将当前类标记为组件
public class MyGlobalFilter implements GlobalFilter, Ordered {
    //继承接口Ordered，实现getOrder方法，返回值越小，优先级越高
    //实现优先级的转换     使得拦截器执行顺序
    @Override
    public int getOrder() {
        return 0;
    }

    @Override
    public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
        // TODO 模拟登陆检验逻辑 待实现
        ServerHttpRequest request = exchange.getRequest();
        HttpHeaders headers = request.getHeaders();
//        System.out.println("headers="+headers);
        //放行
        return chain.filter(exchange);
    }
}
